export default [
  { path: "/", redirect: "/home" },
  { 
    path: "/login", component: () => import("@/views/Login"), 
    name: "Login",
    //路由独享守卫：本地存储有token的情况下只能退出再进入login页面
    beforeEnter: (to, from, next) => {
      if(localStorage.getItem('token')){
        alert('您已登录，请先退出登录再进行登录！')
        next(from.path)
      }else{
        next()
      }
    }
   },
  { path: "/home", component: () => import("@/views/Home"), name: "Home" },
  {
    path: "/goodsShow",
    component: () => import("@/views/GoodsShow"),
    name: "goodsShow",
    meta: {
      keepalive: true // 组件是否需要被保存
  }
  },
  {
    path: `/detail/:id`,
    component: () => import("@/views/Detail"),
    name: "Detail",
  },
  {
    path: "/shopCart",
    component: () => import("@/views/ShopCart"),
    name: "ShopCart",
  },
  {
    path: "/paying",
    component: () => import("@/views/Paying"),
    name: "Paying",
    //路由独享守卫：paying即使登录了也只能从detail和shopCart页面进去
    beforeEnter: (to, from, next) => {
      if(from.path == '/detail/:id' || from.path == '/shopCart'){
        next()
      }else{
        next(from.path)
      }
    }
  },
  {
    path: "/center",
    component: () => import("@/views/Center"),
    name: "Center",
  },
];
